package com.cy.pj.brand.controller;

import com.cy.brand.service.BrandService;
import com.cy.pj.brand.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class BrandController{
    @Autowired
    private BrandService brandService;
    @GetMapping(value={"/brand/doFindBrands/{name}","/brand/doFindBrands"})
    public String doFindBrands(@PathVariable(required = false) String name, Model model){
        List<Brand> list=brandService.findBrands(name);
        model.addAttribute("list", list);
        return "brand/brand";//第一个brand为目录,第二brand为view name
    }
    @GetMapping("/brand/doDeleteById/{id}")
    public String doDeleteById(@PathVariable Integer id,Model model){
        brandService.deleteById(id);
        List<Brand> list=brandService.findBrands(null);
        model.addAttribute("list",list);
        return "brand/brand";
    }
}